<script setup lang='ts'>
import { onMounted, ref,inject } from 'vue';
import { searchForES3DTilesetValues } from '../../../../scripts/general';
import { copyClipboard } from './base/copyClipboard';
import { XbsjEarthUi } from '../../../../scripts/xbsjEarthUi';
const xbsjEarthUi = inject('xbsjEarthUi') as XbsjEarthUi
const p = withDefaults(defineProps<{
    modelValue?: string,
    readonly?: boolean,
    name: string
}>(), { readonly: false, name: '' })
const emits = defineEmits(["update:modelValue", "ondrop", "ondragover", "ondragleave"]);
const list = ref<{ [key: string]: any }>()
list.value = searchForES3DTilesetValues(xbsjEarthUi, false)
const modelValueRef = ref<{ [key: string]: any }>({ id: '', name: '地形图层' })
const leftulisShow = ref(false)
const changeSelect = (item: { [key: string]: any }) => {
    modelValueRef.value = item
    emits('update:modelValue', item.id)
    console.log(modelValueRef.value);
    leftulisShow.value = false
}
onMounted(() => {
    modelValueRef.value = p.modelValue ? { id: p.modelValue, name: '瓦片' } : { id: '', name: '地形图层' }
})

const inputHandler = (e: any) => {
    emits('update:modelValue', (e.target.value).toString())
}
</script>

<template>
    <div v-if="!readonly"  @drop.stop="emits('ondrop', $event)"
        @dragover.stop="emits('ondragover', $event)" @dragleave.stop="emits('ondragleave', $event)">
        <div class="select" style="width: 100%;height: 100%;" v-if="name === '瓦片图层'">
            <div @click.stop.prevent="leftulisShow = !leftulisShow">{{ modelValueRef.name }} <span
                    class="images_xiaosanjiao" :class="leftulisShow ? 'images_xiaosanjiao_transform' : ''"></span>
            </div>
            <ul v-show="leftulisShow">
                <li v-for="item in list" @click="changeSelect(item)">{{ item.name }}</li>
            </ul>
        </div>
        <input type="text" :value="modelValue" @input="inputHandler($event)" v-else />
    </div>
    <div v-else class="aa">
        <div title="双击复制" @dblclick="copyClipboard(modelValue ?? '')">{{ modelValue }}</div>
    </div>
</template>

<style scoped>
input {
    line-height: 26px;
    display: inline-block;
    width: 100%;
    height: 26px;
    background: rgba(28, 28, 29, 0.6);
    border-radius: 4px;
    border: 1px solid #3b3c40;
    margin-right: 0;
    color: rgba(230, 230, 230, 1);
    padding-left: 11px;
    box-sizing: border-box;
}

input:hover {
    border: 1px solid #2c68f7;
}

input:focus {
    border: 1px solid #2c68f7;
}

.aa {
    /* width: 190px; */
    overflow: hidden;
    /* height: 100%; */
    /* display: flex; */
    /* flex-wrap: nowrap; */
    /* justify-content: flex-start; */
    align-items: center;
    /* user-select: none; */
    color: rgba(230, 230, 230, 1);
    font-size: 14px;
    white-space: nowrap;


}

.select {
    width: 100%;
    display: flex;
    align-items: center;
    font-size: 14px;
    line-height: 26px;
    color: rgba(230, 230, 230, 1);
    position: relative;
}

.select>div {
    height: 26px;
    width: 100%;
    background: rgba(28, 28, 29, 0.6);
    border-radius: 4px;
    border: 1px solid #3b3c40;
    color: rgba(230, 230, 230, 1);
    padding-left: 11px;
    box-sizing: border-box;
    cursor: pointer;
    overflow: hidden;
}

.select>ul {
    position: absolute;
    z-index: 20;
    max-height: 100px;
    left: 0;
    top: 16px;
    overflow-y: auto;
    background: #292a2e;
    box-shadow: 0px 2px 6px 0px rgba(26, 26, 28, 0.68);
    border-radius: 4px;
    overflow-x: hidden;
}

.select>ul::-webkit-scrollbar {
    width: 3px;
    background-color: rgba(41, 42, 46, 1);
    border-radius: 2px;
}

.select>ul::-webkit-scrollbar-thumb {
    background-color: rgba(183, 183, 183, 1);
    border-radius: 2px;
}

.select>ul>li {
    list-style: none;
    width: 180px;
    height: 20px;
    font-size: 14px;
    line-height: 20px;
    cursor: pointer;
    text-align: left;
    padding-left: 10px;
    margin-left: -40px;
    white-space: nowrap;
    color: rgba(230, 230, 230, 1);
}

.select>ul>li:hover {
    background: #37393e;
}
</style>